﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core.Property;

namespace Cofe.Core.Filter
{
    public static class FilterCollectionsExtensions
    {
        private static FilterCollections combineFilter(FilterCollections f1, params IFilter[] filters)
        {
            return FilterCollections.FromFilters(f1.AllFilters.Union(filters).ToArray());
        }

        private static FilterCollections combineFilter(FilterCollections f1, FilterCollections f2)
        {
            return FilterCollections.FromFilters(f1.AllFilters.Union(f2.AllFilters).ToArray());
        }

        public static FilterCollections AndEntryType(this FilterCollections fc, string entryType)
        {
            return combineFilter(fc, new PropertyEntryFilter(CofeProperties.Type, entryType));
        }

        public static FilterCollections AndNotEntryType(this FilterCollections fc, string entryType)
        {
            return combineFilter(fc, new PropertyEntryFilter(CofeProperties.Type, entryType, "-"));
        }

        public static FilterCollections AndProperty(this FilterCollections fc, object property, string value)
        {
            return combineFilter(fc, new PropertyEntryFilter(property, value));
        }

        public static FilterCollections AndFilterString(this FilterCollections fc, string filterStr)
        {
            return combineFilter(fc, FilterCollections.FromFilterString(filterStr));
        }

        public static FilterCollections AndParseName(this FilterCollections fc, string parseName)
        {
            return combineFilter(fc, FilterCollections.FromParseName(parseName));
        }

        public static FilterCollections AndName(this FilterCollections fc, string name)
        {
            return combineFilter(fc, FilterCollections.FromName(name));
        }

        public static FilterCollections AndParentParseName(this FilterCollections fc, string parentParseName)
        {
            return combineFilter(fc, FilterCollections.FromParentParseName(parentParseName));
        }

        public static FilterCollections AndPropertyHost(this FilterCollections fc, IPropertyHost propertyHost)
        {
            return combineFilter(fc, FilterCollections.FromPropertyHost(propertyHost));
        }

        public static FilterCollections AndGuid(this FilterCollections fc, Guid id)
        {
            return combineFilter(fc, FilterCollections.FromGuid(id));
        }

        public static FilterCollections AndParentGuid(this FilterCollections fc, Guid parentGuid)
        {
            return combineFilter(fc, FilterCollections.FromParentGuid(parentGuid));
        }
    }
}
